function [Xu,gu,nw,x1] = empirical_density_generate_grid_onedimension(nu,boo2,xx2,gr)
%%
% This function generates the covariates and g for unique households, and
% counts the number of unique households in each grid along the baseline 
% consumption dimension only. This is used for making consistent grid space 
% across waves.  

% Inputs: 
% (1) nu: number of unique households 
% (3) boo2: lower bound for each bin 
% (5) xx2: bin index for each data point 
% (6) gr: sorted g, according to X ordering

% Outputs:
% (1) Xu: Unique X values 
% (2) gu: sum of g for each unique X value
% (3) nw: number of individuals in each Xu 
% (4) x1: one-dimensional Xu
%%
Xu=nan(nu,1); gu=nan(nu,1); nw = nan(nu,1);
k=1;

   for j = 1:length(boo2)
       bin_boo = logical((xx2==j));
       % identify individuals in each pair of covariate combination
       Xu(k,:)=boo2(j);
       gu(k,1) = sum(gr(bin_boo)); % net savings for each unique covariate combo
       nw(k,1) = sum(bin_boo); % count number of individuals in the pair of covariate combo
       k=k+1;
   end


x1 = Xu(:,1);

end